import request from '../utils/request';
import axios from 'axios';
const HOST_URL = 'http://localhost:3000';
let token:any = localStorage.getItem('auto_token');
const http = axios.create({
    timeout: 1000,
    headers: {
        token,
    }
  });

export const fetchData = () => {
    return request({
        url: './table.json',
        method: 'get'
    });
};

// 封装程序所需的数据接口
// 登录接口
export const loginFunc = (data={})=> {
    return http.post(`${HOST_URL}/admin/login`,data).then(response=>{
        return response.data;
    })
}
// 注册接口
export const registerFunc = (data={})=> {
    return http.post(`${HOST_URL}/admin/register`,data).then(response=>{
        return response.data;
    })
}
// 获取用户头像和昵称
export const getAvatorNickNameFunc = (data={})=> {
    return http.get(`${HOST_URL}/admin/get_avator_nickname`,{params: data}).then(response=>{
        return response.data;
    })
}

// 获取用户列表
export const userList = (data={})=> {
    return http.get(`${HOST_URL}/admin/list`,{params: data}).then(response=>{
        return response.data;
    })
}

// 获取用户总数量
export const userTotal = (data={})=> {
    return http.get(`${HOST_URL}/admin/total`,{params: data}).then(response=>{
        return response.data;
    })
}

// 删除用户
export const removeUser = (data={})=> {
    return http.post(`${HOST_URL}/admin/remove`,data).then(response=>{
        return response.data;
    })
}

// http://localhost:3000/banner/upload_img
export const uploadPhoto = (data={})=> {
    return http.post(`${HOST_URL}/banner/upload_img`,data).then(response=>{
        return response.data;
    })
}

// http://localhost:3000/banner/upload_img
export const removePhotoFile = (data={})=> {
    return http.post(`${HOST_URL}/banner/delete_img`,data).then(response=>{
        return response.data;
    })
}



